Max = 1
def simple(x):
    x = int(x)
    f = True
    i = 2
    while f:
        if x % i == 0:
            f = False
            break
        i += 1
        if i > x / 2:
            break
    if x == 1:
        f = False
    if x == 2:
        f = True
    return f

def mm(s):
    m = Max
    if s > m:
        m = s
    return m      
Alo= False
smplStr = input()
if len(smplStr) == 4:
    for i in range(4):
        if smplStr[i] not in '0123456789':
            print(0)
            break
        else:
            Alo=True
            for i in range(4):
                f = simple(smplStr[i])
                if f == True:
                    Max = mm(int(smplStr[i]))
                
            for i in range(3):
                f = simple(smplStr[i] + smplStr[i+1])
                if f == True:
                    Max = mm(int(smplStr[i] + smplStr[i+1]))

            for i in range(2):
                f = simple(smplStr[i] + smplStr[i+1] + smplStr[i + 2])
                if f == True:
                    Max = mm(int(smplStr[i] + smplStr[i+1] + smplStr[i + 2]))
            f = simple(smplStr)
            if f == True:
                    Max = mm(int(smplStr))

else: 
    if Alo == False:
        print(0)
    aslsl = input()
    exit()
if Max > 1 and Alo == True and f == True:
    print(Max)
else:
    print(0)
